/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Hua YY
 * Date: 2025-01-03
 * Time: 17:37
 */
class Solution1 {
    public int lengthOfLastWord(String s) {
        int n = s.length();
        StringBuffer buffer = new StringBuffer();
        for (int i = n - 1; i >= 0;) {
            while(i >= 0 && s.charAt(i) == ' '){
                i--;
            }
            while (i >= 0 && s.charAt(i) != ' ') {
                buffer.append(s.charAt(i));
                i--;
            }
            break;
        }
        return buffer.length();
    }
}
public class Test1 {
}
